package jwdt.xadmin.work.action;

import jwdt.common.action.BaseAction;
import jwdt.common.util.CacheUtil;
import jwdt.xadmin.work.bean.TDocClass;
import jwdt.xadmin.work.service.DocClassManageService;

import com.ezerg.db.Jdb;
import com.ezerg.db.ext.PageUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;
import com.ezerg.web.Page;
import com.ezerg.web.annotation.Controller;
import com.ezerg.web.annotation.RequestMapping;

@Controller("/xadmin/work")
public class DocClassManageAction extends BaseAction {
	
	private DocClassManageService docclassManageService = (DocClassManageService)app.getBean("docclassManageService");
	
	@RequestMapping("/listDocClass")
	public Page doListVote(Form f, Module m) throws Exception {
		PageUtil pu = (PageUtil)f.copy2Class(PageUtil.class);
		TDocClass dc = (TDocClass)f.copy2Class(TDocClass.class);
		return m.getWritePage(f, docclassManageService.doList(pu, dc).toJson());
	}
	
	@RequestMapping("/addDocClass")
	public Page doAddact(Form f, Module m) throws Exception {
		TDocClass obj = (TDocClass)f.copy2Class(TDocClass.class);
		return m.getWritePage(f, docclassManageService.doAddact(obj));
	}
	
	@RequestMapping("/editDocClass")
	public Page doEditact(Form f, Module m) throws Exception {
		int classid = f.getInt("classid");
		TDocClass obj = (TDocClass)f.copy2Class(TDocClass.class);
		return m.getWritePage(f, docclassManageService.doEditact(obj, classid));
	}
	
	@RequestMapping("/delDocClass")
	public Page doDel(Form f, Module m) throws Exception {
		int id = f.getInt("classid");
		return m.getWritePage(f, docclassManageService.doDelact(id));
	}
	
	@RequestMapping("/checkDocClass")
	public Page doCheck(Form f, Module m) throws Exception {
		int id = f.getInt("classid");
		int result = f.getInt("result");
		return m.getWritePage(f, docclassManageService.doUpdateState(id, "zt="+result));
	}
	
	@RequestMapping("/listDocClassForTree")
	public Page doLisDocClassForTree(Form f, Module m) throws Exception {
    	return m.getWritePage(f, docclassManageService.doListDocClassForTree());
	}
	
	@RequestMapping("/listDocClassForCombox")
	public Page doListDocClassForCombox(Form f, Module m) throws Exception {
		//生成json字符串
    	return m.getJsonPage(f, Jdb.get().query("select classid, name from t_docclass where zt=1 ORDER BY classid asc", CacheUtil.C0));
	}
	
	@RequestMapping("/docClassWindow")
	public Page doLoad(Form f, Module m) throws Exception {
		int id = f.getInt("classid");
		f.add("obj", docclassManageService.doLoad(id));
		return m.findPage("/xadmin/work/docClassWindow");
	}
}
